<HTML>

<head>
  <title>login</title>
  <script src="Scripts/jquery-1.5.1.js" type="text/javascript"></script>
  <script type="text/javascript" language="JavaScript">

   $(function () {

      $("#submit").click(function () {

        var returnValue = true;

          var txtName = $("#userNameInput").val();
          var txtPassword = $("#userPasswordInput").val();

          var db = getCurrentDb();

//"SELECT * FROM usertable where username='".$nameInput."'"
//if exists (select * from sysdatabases where name='databaseName')
          db.transaction(function (trans) {
               trans.executeSql("select * from Register where  userName=?", [txtName], function (ts, data) {
                    if (data) {
                             for (var i = 0; i < data.rows.length; i++) {
                                var row =data.rows.item(i);//获取某行数据的json对象
                                if (row.userPassword==txtPassword){
                                    alert("登录成功！");
                                    returnValue=true;
                                    window.location.href="showData.html";
                                    return;
                                  }
                             }
                            alert("账号或密码错误！");
                            returnValue=false;
                            return;
                        
                      }

                   
                }, function (ts, message) {
                    alert(message);
                    var tst = message;
                });


            });
          return returnValue;
      });
  });

  function getCurrentDb() {
      //打开数据库，或者直接连接数据库参数：数据库名称，版本，概述，大小
      var db = openDatabase("myDb", "1.0", "it's to save register data!", 1024 * 1024); ;
      return db;
       
  }

  </script>
  <link rel="stylesheet" type="text/css" href="register.css" />
</head>

<body>

  <h1>欢迎登录！</h1> 
  <div class="upView">
</div>

<div class="three">
<form  name="loginForm">
  <fieldset>
     <div><label>用户名: <input type="text" name="userNameInput" id="userNameInput" size="20"></label></div><br />
      <div><label>&nbsp密码: <input type="password" name="userPasswordInput" id="userPasswordInput" size="20" maxlength="20"></label></div><br/>
  </fieldset>

  <fieldset>
       <div class="submit"><input type="button" name="submit" id="submit" value="登录" /></div>
  </fieldset>

</form>
</div>
</body>
</html>